<?php
include_once('common/header.php');			
if($AppUI->id <=0 || !isset($_SERVER['HTTP_REFERER'])) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$intOfflineId = $objRequest->getParam('offlineid', 0);
$intOjoinId   = $objRequest->getParam('ojoinid', 0);
$intAjax 	  = $objRequest->getParam('aj', 0);
$intUserId 	  = Vfriend_Function::base64D($objRequest->getParam('uid', 0));
$intPoint 	  = $objRequest->getParam('po', 0);
$strToken 	  = $objRequest->getParam('token', '');
$strConstSess = ($intPoint == 1) ? SE_OFFLINE_RATE_RIGHT : SE_OFFLINE_RATE_WRONG;
$intConstSess = ($intAjax == 1) ? $intOjoinId : $intOfflineId;
$strSession	  = Vfriend_Function::getSecret($intConstSess, $strConstSess);
$strRefer	  = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$objVfriendUser	= new Vfriend_User();
$objUser		= $objVfriendUser->getFull($intUserId);
$intError		= '';
$strMessage		= '';
$strData		= '';
$strLink		= '';

if(Vfriend_Function::isValidLink($strRefer) && $strToken != '' && $strToken == $strSession) {	
	Vfriend_Function::deleteSecret($intConstSess, $strConstSess);
	$objOffline	= new Offline();
	$intError	= $objOffline->orateAdd($AppUI->id, $intUserId, $intOfflineId,$intPoint);
	if($intError == 0) {
		$strMessage = $arrMessage[13];
		$strMessage	= str_replace('[strFullname]', $objUser->fullnamevn, $strMessage);
		if($intAjax == 1) {
			$intTotal 	= 0;
			$arrAccepted	= $objOffline->getAllForOjoin($intOfflineId, 3, 0, 500, $intTotal, 1);
			if($intTotal == 0) {
				$strLink = $strRefer;
			}
			$this->view->arrAccept		= $arrAccepted;
			$this->view->intOfflineId 	= $intOfflineId;
			$objView 	= Zend_Registry::get('objView');
			$strData	= $objView->fetch('ajax/box-offline-rate-item.tpl');			
		}
	}else {
		$intError	= $intError+29;
	}
}else {
	$intError = 29;
}
if($intError > 0){
	$strError 	= $arrError[$intError];
	$strError	= str_replace('[strFullname]', $objUser->fullnamevn, $strError);
	if($intAjax) {
		$strMessage	 = $strError;
		$strMessage	 = str_replace('\n', "\n", $strMessage);
	}
}
if($intAjax == 0) { 
	if($intError == 0) {		
		Vfriend_Function::setMsg($strMessage);
	} else {		
		Vfriend_Function::setError($strError);
	}
	$strRefer = $strRefer != '' ? $strRefer : LINK_OFFLINE;
	Vfriend_Function::redirect($strRefer);
} else {
	$arrJson 		= array('error'=>$intError, 'msg'=>$strMessage, 'data'=>$strData, 'link'=>$strLink);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
?>